using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemDrop : MonoBehaviour
{
    [SerializeField] private GameObject dropPrefab;
    private Vector2 velocity=new Vector2(5,8);
    [SerializeField] private ItemData[] dropitemDataArray;
    private List<ItemData> dropitemDataList;
    private void Start()
    {
        dropitemDataList = new List<ItemData>();
    }
    protected void Drop(ItemData item)
    {
        GameObject drop = Instantiate(dropPrefab, transform.position, Quaternion.identity);
        drop.GetComponent<ItemObject>().SetupItem(item, velocity);
    }
    public virtual void RandomDropItem()
    {
        for(int i=0;i< dropitemDataArray.Length; i++)
        {
            if (Random.Range(0, 100) <= dropitemDataArray[i].dorpChance)
                dropitemDataList.Add(dropitemDataArray[i]);
        }
        if (dropitemDataList.Count == 0) return;
        ItemData itemData = dropitemDataList[Random.Range(0, dropitemDataList.Count - 1)];
        Drop(itemData);
    }
}
